Skip to content

Fixes #38480: Enable MCP sign-in with a public OIDC client - #38701

Merged
Vishnuujain merged 9 commits into
open-metadata:mainfrom
iamkiayun:fix/mcp-public-oidc-sign-in
Nov 27, 2026
Merged

Vishnuujain merged 9 commits into
open-metadata:mainfrom
iamkiayun:fix/mcp-public-oidc-sign-in

Conversation

@iamkiayun

@iamkiayun iamkiayun commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38480

Public OIDC deployments currently send the MCP client back with authorization_failed before the identity provider sees the login. This change uses the configured public client ID and registered callback to exchange an authorization code with S256 PKCE, without a client secret. It reuses the existing state, identity and consent checks. The provider registration must support server-side code redemption for a public client.

The regression signs in through a local identity provider, approves consent and calls get_user_context as the expected user. It checks the code exchange, then refreshes and revokes the grant. The focused suites also cover confidential and ordinary public-client sign-in. No live identity-provider tenant was used.


Summary by Gitar

  • Public MCP discovery:
    • Discovers provider endpoints from the public authority, refreshing at most once per minute and pinning the issuer
    • Refuses HTTP redirects and applies outbound URL checks to discovery, token and key-set requests
  • Entra tenant handling:
    • Accepts tenant-templated issuers and rejects signing keys whose issuer scope does not match the token
  • MCP token verification:
    • Verifies the MCP ID token inside the callback before any user is provisioned or session activated
  • Documentation:
    • Added ADR amendment covering public client registration, PKCE and Entra single-page application redirects
    • Added MCP callback registration notes to the Auth0, Cognito, custom OIDC and other SSO setup guides
  • Sign-in errors:
    • Returns HTTP 502 with registration guidance when the provider rejects the server-side code exchange

This will update automatically on new commits.

@iamkiayun
iamkiayun requested a review from a team as a code owner November 25, 2026 14:11
@iamkiayun
iamkiayun requested a review from yan-3005 November 25, 2026 14:11
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@Vishnuujain Vishnuujain self-assigned this Nov 25, 2026

@Vishnuujain Vishnuujain left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran this locally, tests pass. left a couple of comments, the azure one would break existing setups so that one's important

allowed = attributes.get("issuer") instanceof String scope && isIssuedBy(scope, token);
} else {
final String keySetPath = URI.create(publishedKey.keySetUrl()).normalize().getPath();
allowed = !templated && !SHARED_ENTRA_KEY_SET.matcher(keySetPath).matches();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaks azure. common/discovery/keys doesn't have issuer on any key, and that's the url our docs ask people to set. so confidential setups would fail too, not just public. maybe only do this check when the issuer has {tenantid}?

new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL url) throws IOException {
OutboundUrlPolicy.getInstance().checkForConnect(uri);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the first key url gets blocked (like http://127.0.0.1:8585/...), this throws and the other urls never get tried. could it throw an IOException instead so it's treated like a normal failed download?

this.sessions = sessions;
}

synchronized AuthenticationCodeFlowHandler forMcp(String configuredBaseUrl) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when discovery fails, every sign-in tries it again inside this lock and waits out the timeout. can we remember the failure for a minute or so?

authority += "/v2.0";
}
final String discovery = authority + DISCOVERY_PATH;
ValidationHttpUtil.validateUrl(discovery);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if someone sets the idp by ip (http://10.0.0.5:8080/...) it gets refused here, and the client just sees "SSO handler not initialized". maybe add a line in the docs that it needs a hostname?

@harshach

Copy link
Copy Markdown
Collaborator

@iamkiayun thanks for the PR. Please address the comments above

@iamkiayun

Copy link
Copy Markdown
Contributor Author

@harshach @Vishnuujain I addressed all four review comments in fcdedf85b and made the requested single-return cleanup in f3c7fa0ff. Existing fixed-tenant Azure configurations accept legacy signing keys without an issuer field while still checking the token’s tenant. A blocked key URL now falls through to the next allowed source, initial discovery failures are cached for one minute, and the setup guide documents the provider hostname requirement.

On f3c7fa0ff, all 219 focused unit tests and all 62 PostgreSQL/OpenSearch integration tests passed with local identity providers. I haven’t tested against a live Microsoft tenant. Could you re-review the latest commit?

@IceS2 IceS2 removed their assignment Nov 26, 2026
@Vishnuujain

Vishnuujain commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

@iamkiayun thanks, tested again on 25904d6 merged with main, all good.

one more thing, docs:

  • our web app uses id_token by default, so most setups only have that on. mcp needs code, so admins have to turn on code grant and add <om-url>/mcp/callback as a redirect
  • this is only in the mcp README right now. can you add it to the SSO guides in the UI (public/locales/en-US/SSO/*.md)?
  • for entra, say where to add the /mcp/callback redirect, SPA won't work
  • multi-tenant azure with the old keys url is now blocked for mcp. fine if intended, just add a line about it

@gitar-bot

gitar-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 3 closed / 3 findings

Adds public-client OIDC code exchange and changes MCP ID-token validation, so issuer or key-validation errors could admit an unintended identity or block sign-in.

Enables MCP sign-in against public OIDC clients by exchanging authorization codes with S256 PKCE using the configured public client ID and registered callback, with no client secret. Public discovery now refreshes at most once per minute with issuer pinning, and the ADR gained an amendment covering public client registration.

The previously open findings on the missing decision record, the uncovered discovery refresh and failure cache, and the early returns in forMcp were all addressed. No issues remain open.

✅ 3 closed
✅ Quality: No decision record covers how the public MCP client is derived

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PublicOidcAuthServletHandler.java:44-58 📄 docs/decisions/2026-10-30-the-mcp-callback-needs-the-state-of-a-pending-login.md:30-37
publicCodeFlow decides how the server reaches the IdP for a public client. It builds the discovery document from authority + /.well-known/openid-configuration and adds /v2.0 for AZURE authorities. It uses the MCP/system base URL as the OIDC serverUrl and falls back to <base>/callback when no callback is configured. These URLs are derived formats that the provider registration has to match, and they are judgment calls. The amendment added to the 2026-10-30 record only says the registration must allow a server-side exchange and register /callback. It does not state the derivation. Following the decision-records guidance, the amendment (or a new record) should say something like: "For a public OIDC client, MCP discovers the provider at <authority>/.well-known/openid-configuration (Azure: <authority>/v2.0/...), uses the MCP base URL as its server URL, and redirects to the configured callback URL or <base>/callback; no other oidcConfiguration setting (scope, prompt, max age, custom params) applies."

✅ Quality: Public discovery refresh, failure cache and issuer pinning have no record

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PublicOidcConfiguration.java:27 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PublicOidcConfiguration.java:40-45 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PublicOidcConfiguration.java:66-80 📄 docs/decisions/2026-10-30-the-mcp-callback-needs-the-state-of-a-pending-login.md:30-44
This commit adds several rules to the public MCP flow. Provider discovery is re-fetched every minute (DISCOVERY_INTERVAL_NANOS). A failed discovery is cached and rethrown for that same minute, so one transient provider error blocks every public MCP sign-in for up to 60 seconds. A refresh that reports a different issuer is refused, and discovery, token and key-set requests never follow redirects. These are judgment-call values and correctness rules that you can't see from one file. The amended record in docs/decisions/2026-10-30-... covers only the client ID, the discovery URL and the callback registration, so none of them is recorded.

The amendment would need a sentence like: "Public MCP rediscovers the provider at most once a minute. A failed discovery is reused for that minute. A rediscovered issuer must equal the first one seen, and provider requests are sent to the discovered URL without following redirects."

✅ Quality: forMcp now has an early return and a mid-try return, against the ADR

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PublicOidcAuthServletHandler.java:48-62
Before this commit, forMcp returned once, at the end. It now has an early return handler; when a handler is cached (line 56) and a second return handler; inside the try (line 69). That contradicts the Accepted record ADR:2026-11-20-a-method-returns-once, which says a Java method "has at most one return, and it is the last statement" and that "a change that touches a method brings it into line". This is blocking: either restructure the method or add a record that supersedes that one.

Fix: wrap the cache-miss path in if (handler == null), move the discovery attempt into a helper that assigns handler or rethrows the cached failure, and keep a single return handler; as the last statement.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Vishnuujain Vishnuujain added the To release Will cherry-pick this PR into the release branch label Nov 27, 2026
@Vishnuujain
Vishnuujain enabled auto-merge (squash) November 27, 2026 09:33
@iamkiayun

Copy link
Copy Markdown
Contributor Author

Thanks for the approvals. The backend run has one failing service test: AsyncServiceTest.testShutdownNowClearsMetricsForQueuedDatabaseTasks. It checks cancellation of a queued database task during shutdown. The sign-in tests passed, and this PR doesn’t change the async executor or that test. I tried to rerun the failed job but lack permission. Could a maintainer retry it on 907c768?

@Vishnuujain

Copy link
Copy Markdown
Contributor

@iamkiayun re runned the test, it was flaky earlier

@Vishnuujain
Vishnuujain merged commit 0ea3fea into open-metadata:main Nov 27, 2026
53 of 57 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #38965 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Not backported to 2.0. Claude looked at the conflict and declined to resolve it:

Backport aborted: #38701 → 2.0

Reason

PR #38701 ("Fixes #38480: Enable MCP sign-in with a public OIDC client") is
built directly on top of a chain of prior main-only changes to the OIDC/SSO
authentication subsystem that were never backported to 2.0:

None of these landed on 2.0. Concretely:

Applying just #38701's diff would mean silently reinventing or dragging in
several prior PRs' worth of unrelated production authentication logic
(IdentityProviderKeys, large parts of AuthenticationCodeFlowHandler, and a
whole new test harness) as a side effect of this backport — far beyond "port
this change and nothing else," and too risky to resolve heuristically inside
a single conflict-resolution pass.

What did merge cleanly

Cherry-pick auto-resolved (now staged, part of Changes to be committed)
before this review:

  • openmetadata-mcp/README.md
  • openmetadata-mcp/.../provider/UserSSOOAuthProvider.java
  • openmetadata-service/.../security/AuthServeletHandlerFactory.java,
    AuthServeletHandlerRegistry.java, NoopAuthServeletHandler.java
  • New files PublicOidcAuthServletHandler.java / PublicOidcConfiguration.java
    and their tests
  • ProviderTokenValidatorTest.java (partially — see caveat below)
  • SSO client-config locale docs (en-US/SSO/*.md)

These pieces are the self-contained "public OIDC client" addition and don't
depend on the missing IdentityProviderKeys infrastructure, but since the
unmerged files they depend on (ProviderTokenValidator.java,
AuthenticationCodeFlowHandler.java, McpCallbackServlet.java,
IdTokenValidator.java) are still conflicted/unresolved, the auto-merged
files above are not usable on their own — they're part of the same
change and must land together.

Recommendation

Before #38480/#38701 can be backported to 2.0, the prerequisite chain needs
to land first, in order:

  1. Fixes 35799: Integration tests that sign in through mock identity providers #35894 ("Integration tests that sign in through mock identity providers")
  2. Fixes 35799: Look key ids up in the key sets in configured order #35929 ("Look key ids up in the key sets in configured order")
  3. fix(security): third batch of backend security-hardening fixes #36952 (security-hardening batch that touches the same files)
  4. fix(sso): return clear errors and keep login working on misconfiguration #37741 ("return clear errors and keep login working on misconfiguration")

Each should be backported and verified independently before re-attempting
#38701, since each is a non-trivial production change to the authentication
path in its own right.

Repository state

The cherry-pick has been left mid-flight (git status shows the same
conflicted/unmerged paths as before this review). No conflict markers were
resolved and nothing further was staged or committed.

resolver run

Vishnuujain pushed a commit that referenced this pull request Nov 27, 2026
…38965)

* Fix MCP sign-in for public OIDC clients (#38480)

* Bind public MCP sign-in to its callback and provider configuration

* Document public MCP discovery refresh and connection rules

* Preserve legacy Azure sign-in and recover from provider discovery failures

* Use a single return in the public MCP handler cache

* Preserve public OIDC discovery failures after the pac4j upgrade

* Document the additional MCP callback in the SSO setup guides

* Distinguish the MCP authorization grant from its response type

(cherry picked from commit 0ea3fea)

Co-authored-by: Kia Yun <kiayun.0218@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP sign-in fails when SSO is configured as a public client

5 participants